package muilty_thread.pic_java_design_pattern.GuardedSuspension;

import lombok.SneakyThrows;

import java.util.Random;

/**
 * @version: 1.0
 * @Description: TODO
 * @author: zZmH
 * @date: 2020/10/12 00:31
 */


public class ServerThread implements Runnable{

    private final Random random;
    private final RequestQueue queue;

    public ServerThread(Random random, RequestQueue queue) {
        this.random = random;
        this.queue = queue;
    }

    @SneakyThrows
    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            Request request = queue.getRequest();
            System.out.println(Thread.currentThread().getName() + "requests: " + request);
            try {
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
